package com.chenxin.interact.api;

import com.chenxin.common.annotation.InterfaceLogs;
import com.chenxin.common.constant.WmsConstants;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.core.domain.ProcResult;
import com.chenxin.interact.domain.mesRequest.MesInReqDTO;
import com.chenxin.interact.domain.mesRequest.MesOrderReqDTO;
import com.chenxin.interact.domain.mesRequest.MesReturnReqDTO;
import com.chenxin.interact.process.IMesInteractProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("mes/interact")
public class MesAPI extends BaseController {

    @Autowired
    private IMesInteractProcess mesInteractProcess;

    /**
     * 新增mes发料接口
     */
    @InterfaceLogs(name = "mes发料接口")
    @PostMapping("/order")
    public AjaxResult orderRequest(@RequestBody MesOrderReqDTO mesOrderReqDTO) {

        ProcResult result = mesInteractProcess.procMesOrder(mesOrderReqDTO);

        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "mes退料接口")
    @PostMapping("/return")
    public AjaxResult returnRequest(@RequestBody MesReturnReqDTO mesReturnReqDTO) {

        ProcResult result = mesInteractProcess.procMesReturn(mesReturnReqDTO);

        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    /**
     * mes成品入库接口
     *
     * @param mesInReqDTO
     * @return
     */
    @InterfaceLogs(name = "mes入库接口")
    @PostMapping("/in")
    public AjaxResult inRequest(@RequestBody MesInReqDTO mesInReqDTO) {

        ProcResult result = mesInteractProcess.procMesIn(mesInReqDTO);

        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }
}
